/* Listing pattern */

@import "@patternfly/patternfly/sass-utilities/colors.scss";
@import "./variables.scss";

.listing-ct-heading,
.listing-ct-actions {
    margin: 0.5rem 0;
}

.listing-ct-heading,
.listing-ct-simplebody-actions {
    flex: auto;
    padding: 0.25rem 1em 0.25rem 0;
}

/* A listing item is a row in the table */
tbody > tr.listing-ct-item {
    border: 1px solid transparent;
    border-top: 1px solid var(--ct-color-list-border);
    cursor: pointer;
}

tbody > tr.listing-ct-item.listing-ct-warning {
    background-color: $listing-ct-warning-color;
}

tbody.open > tr.listing-ct-item,
tbody.open > tr.listing-ct-panel {
    background-color: $listing-ct-active;
    border-bottom: none;
    border-top: none;
    border-left: 1px solid $listing-ct-border;
    border-right: 1px solid $listing-ct-border;
    transition: all 200ms;
}

tbody.open > tr.listing-ct-item td,
tbody.open > tr.listing-ct-item th {
    border-top: 1px solid $listing-ct-border;
}

tbody.open td div.listing-ct-head {
    background-color: $pf-color-white;
    align-items: flex-end;
}

tbody.open > .listing-ct-panel > td > .listing-ct-body {
    border: none;
    overflow: auto;
}

tbody.open > tr.listing-ct-panel + tr.listing-ct-body {
    border-top: none;
}

tbody.open > tr.listing-ct-panel td div.listing-ct-head {
    border: none;
    border-bottom: 1px solid $listing-ct-border;
    padding-top: 0;
}

/* use hover color expanded rows even if navigation isn't available */
tbody.open > tr.listing-ct-item:hover {
    background-color: $listing-ct-hover;
}

@keyframes listingCtToggleOpen {
    0% {
       transform-origin: 50% 50%;
       transform: translate(0, -1px) rotate(-90deg);
    }
    100% {
       transform: translate(0, 0) rotate(0);
    }
}

/* Listing items have decent padding ... */
.listing-ct > thead > tr > th,
tr.listing-ct-item > th,
tr.listing-ct-item > td {
    padding: $listing-ct-padding * 1.5;
    vertical-align: text-top; /* baseline doesn't support wrapped lines */
}

tr.listing-ct-item > td {
    > .pf-c-button {
        margin-top: -7px;
        margin-bottom: -7px;
    }
}

/* Listing actions can be used directly as a cell */
tr.listing-ct-item td.listing-ct-actions,
td.listing-ct-actions {
    padding: $listing-ct-padding * 0.5 $listing-ct-padding;
    text-align: right;
    float: none;
}

/* if the entire row is selected, highlight */
tr.listing-ct-item.listing-ct-selected {
    background-color: $pf-color-blue-400;
    color: $pf-color-white;
    border-color: multiply($pf-color-black-200, $pf-color-blue-400);

    &:hover {
        background-color: multiply($pf-color-black-200, $pf-color-blue-400);
        border-color: multiply($pf-color-black-200, $pf-color-blue-400);
    }
}

tr.listing-ct-item.listing-ct-selected .badge {
    background-color: multiply($badge-bg, $pf-color-blue-400);

    &:hover {
        background-color: multiply($badge-bg, $pf-color-blue-500);
    }
}

.listing-ct-head .listing-ct-actions {
    margin: 0.25rem 0;
    order: -1;
}

/* The last column of a listing is always right aligned */
tr.listing-ct-item td:last-child {
    text-align: right;
}

div.listing-ct-panel {
    box-shadow: 1px 1px 1px 1px $listing-ct-open;
    margin-bottom: $listing-ct-spacing;
}

div.listing-ct-maybe {
    border: 1px dashed $listing-ct-border-maybe;
    box-shadow: none;
}

div.listing-ct-head {
    padding: $listing-ct-padding $listing-ct-padding 0 $listing-ct-padding;
    background-color: $listing-ct-open;
    border-color: $listing-ct-border;
    border-style: solid;
    border-width: 1px 1px 0 1px;
    overflow: hidden;
    align-items: center;
}
table:not(.pf-c-table) div.listing-ct-head {
    display: flex;
    flex-flow: row-reverse wrap;
}

div.listing-ct-head:last-child {
    padding-bottom: $listing-ct-padding;
}

div.listing-ct-maybe div.listing-ct-head,
div.listing-ct-maybe div.listing-ct-body {
    background-color: $pf-color-white;
    border: none;
}

tbody.active .listing-ct-head {
    border-top: $listing-ct-open-width solid var(--ct-color-link);
}

.listing-ct-head h3 {
    font-weight: normal;
    font-size: 18px;
    margin-top: 0px;
    margin-left: $listing-ct-padding * 0.5;
    margin-bottom: $listing-ct-padding;
}

.listing-ct-head h3 i {
    float: left;
    padding-right: 7px;
}

.listing-ct-head .pf-c-nav {
    flex: auto;
}

/* To display info instead of tabs */
.listing-ct-head dl {
    display: inline-block;
    height: 1.6em;
    margin-bottom: 5px;
    white-space: nowrap;
    margin-right: 45px;
    margin-left: 5px;
}

.listing-ct-head dt {
    font-weight: normal;
    display: inline;
    margin-right: 0.5em;
    color: $listing-ct-metadata;
}

.listing-ct-head dd {
    display: inline;
    color: black;
}

.listing-ct-body {
    padding: $listing-ct-padding * 2 $listing-ct-padding + $listing-ct-spacing;
    border: 1px solid $listing-ct-border;
    background-color: $pf-color-white;
}

.listing-ct-inline > td > .listing-ct-body {
    border: none;
    padding-top: 0px;
    padding-left: $listing-ct-padding * 2;
    padding-bottom: 0px;
}

.listing-ct-inline > h3 {
    border-top: 1px solid $listing-ct-border;
    padding-top: 20px;
    margin-top: 30px;
}

.listing-ct-inline > h3:first-child {
    border-top: none;
    padding-top: 0px;
    margin-top: 20px;
}

.listing-ct-actions {
    float: right;
    min-height: 26px;
}

.listing-ct-status {
    float: right;
    clear: right;
}

.listing-ct-error {
    border-top: 1px solid $listing-ct-border;
    border-left: 1px solid $listing-ct-border;
    border-right: 1px solid $listing-ct-border;
}

.listing-ct-error.alert {
    margin-bottom: 0;
}

.listing-ct-body tt {
    font-size: 12px
}

.listing-ct-body dl {
    margin: 0;
}

.listing-ct-body dl dd dl.inline-dl dt,
.listing-ct-body dt {
    clear: left;
    float: left;
    width: 100px;
    min-height: 26px;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: $listing-ct-metadata;
    font-weight: normal;
}

.listing-ct-body dt {
    text-align: right;
}

.listing-ct-body dl dd dl dt {
    text-align: left;
}

.listing-ct-body dd {
    margin-left: 110px;
    min-height: 26px;
    max-width: 1000px;
    text-overflow: ellipsis;
}

.listing-ct-body dl.full-width dt {
    text-align: left;
    min-width: none;
    max-width: none;
    float: none;
    width: auto;
}

.listing-ct-body dl.full-width dd {
    margin-left: 0px;
}

/* By default these are hidden */
/* (HACK: Special-case the user auth dialog) */
tbody:not(.ssh-key-body) > tr.listing-ct-head,
tbody > tr.listing-ct-panel,
tbody > tr.listing-ct-body {
    display: none;

    > td {
        /* Compensate for the left-side blue highlight */
        padding-left: 3px;
    }
}

/* ... unless they are in the right state */
tbody.open > tr.listing-ct-head,
tbody.open > tr.listing-ct-panel,
tbody.open > tr.listing-ct-body {
    display: table-row;
}

/* Animate the listing head & the last visible body */
/* (Switching tabs will adds new listing-ct-bodys & toggle visibility) */
tbody.open div.listing-ct-head,
tbody.open div.listing-ct-head + div.listing-ct-body:not([hidden]):last-child {
    animation: listingCtShow 100ms ease-in-out;
}

@keyframes listingCtShow {
    0% {
        margin-bottom: 0;
        margin-top: 0;
        max-height: 0;
        opacity: 0;
        padding-bottom: 0;
        padding-top: 0;
        line-height: 0;
    } 50% {
        opacity: 0;
        line-height: 1;
    }
    100% {
        max-height: 100vh;
        opacity: 1;
    }
}

/* Turn off animation if requested by the browser/OS (where supported) */
@media (prefers-reduced-motion: reduce) {
    tbody.open div.listing-ct-head,
    tbody.open div.listing-ct-body {
        animation: none;
    }
}

tbody.open tr.listing-ct-head {
    border-color: $listing-ct-border;
    border-style: solid;
    border-width: 1px 1px 0 1px;
    border-top: $listing-ct-open-width solid var(--ct-color-link);
    background-color: $listing-ct-open;
}

tr.listing-ct-head + tr.listing-ct-head {
    border-top: none;
}

tr.listing-ct-head + tr.listing-ct-head td {
    padding: 0px $listing-ct-padding 0px $listing-ct-padding;
}

tr.listing-ct-body td {
    padding: $listing-ct-padding * 2 $listing-ct-padding + $listing-ct-spacing;
    font-size: var(--pf-global--FontSize-s);
}

.listing-ct-empty {
    color: var(--ct-color-subtle-copy);
    text-align: center;
    border-top: 1px solid $listing-ct-border-light;
    border-bottom: 1px solid $listing-ct-border-light;
}

/* Used at the end of a group of tbody to show an 'empty' message */
thead.listing-ct-empty td {
    padding: $listing-ct-padding;
}

tbody + thead.listing-ct-empty {
    display: none;
}

/* Listing pattern defaults to using full width of parent */
.listing-ct-wide {
    width: 100%;
}

div.listing-ct-head {
    overflow: visible;
}

.listing-ct-head .btn-group,
.listing-ct-head button:not(.dropdown-toggle) {
    margin-left: 0.3em;
}

tbody tr.listing-ct-noexpand {
    cursor: default;
}

.listing-ct-item td,
.listing-ct-item th,
.listing-ct-body {
    /* Force wraps when words are too long */
    overflow-wrap: break-word;
    hyphens: auto;
}
.listing-ct-item td,
.listing-ct-item th {
    max-width: calc(100vw - 18rem);
}
.listing-ct-body {
    /* 42 = (20px padding + 1px border) * 2 */
    max-width: calc(100vw - 42px);
}
